package com.ybwh.springboot2.satoken.service.impl;

import com.gitee.fastmybatis.core.support.BaseLambdaService;
import com.github.pagehelper.Page;
import com.google.common.base.Preconditions;
import com.ybwh.springboot2.common.PageParam;
import com.ybwh.springboot2.common.Pagination;
import com.ybwh.springboot2.satoken.mapper.SysRoleMapper;
import com.ybwh.springboot2.satoken.model.entity.SysRole;
import com.ybwh.springboot2.satoken.service.SysRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 服务接口实现类
 * </p>
 *
 * @author Fan Beibei
 * @version V1.0
 * @since 2025-08-03 00:54:02
 */
@Slf4j
@Service
public class SysRoleServiceImpl extends BaseLambdaService<SysRole, SysRoleMapper> implements SysRoleService {
    @Resource
    private SysRoleMapper sysRoleMapper;


    @Override
    public Pagination<SysRole> queryByPage(PageParam<SysRole> pageParam) {
        Preconditions.checkArgument(pageParam.getCurPage() > 0);
        Preconditions.checkArgument(pageParam.getPageSize() > 0);

        Page<SysRole> page = sysRoleMapper.selectByPage(pageParam.getParam(), pageParam.getCurPage(), pageParam.getPageSize());

//        return new PageInfo<>(page);
        return new Pagination<>(page);
    }


//------------以上是生成代码-----------------------------------------------------------------------------------------------------------------

    @Override
    public Long addOrUpdate(SysRole param, Long userId) {

        if (null == param.getId()) {
            save(param);
        } else {
            update(param);
        }


        return param.getId();
    }

}
